package second.thread.exception;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author: heweiwei
 * @time: 2025/3/18 21:08
 * @description:
 */
public class ThreadExceptionTest {

    public static void main(String[] args) {
        test1();
    }

    public static void test1() {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        try {
            executorService.submit(() -> {
                try {
                    int age = 10 / 0;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        } finally {
            executorService.shutdown();
        }
    }

    public static void test2() {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        try {
            executorService.execute(() -> {
                int age = 10 / 0;
            });
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executorService.shutdown();
        }
    }

    public static void test3() {
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        try {
            Future<?> taskFuture = executorService.submit(() -> {
                int age = 10 / 0;
            });
            taskFuture.get();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executorService.shutdown();
        }
    }

}
